home *** CD-ROM | disk | FTP | other *** search
/ AMP Graphics Collection / AMP Graphics Collection.iso / programs / author / dirwin / data.z / ANIMWIZ.DIR / 00009_Script_Zooms < prev    next >
Text File  |  1996-03-15  |  13KB  |  424 lines

  1. -- Zooms script
  2.  
  3. property ioFieldList
  4. property iFieldFocus
  5. property ioFieldFocus
  6. property iCurrentMotionStyleIndex
  7. property iCurrentVisualStyleIndex
  8.  
  9. -- The motion styles are:
  10. property ikMotionIn  -- 1
  11. property ikMotionOut  -- 2
  12. property ikMotionOutThenIn  -- 3
  13. property ikMotionInThenOut  -- 4
  14.  
  15. property iFirstTIme
  16. property iSaveSeconds
  17. property iSaveFPS
  18. property iSaveBaseline
  19. property iSaveDelayEnter
  20. property iSaveDelayHold
  21. property iSaveMark
  22. property iSaveCycles
  23. property iSaveSizeMin
  24. property iSaveSizeMax
  25.  
  26.  
  27. on birth me
  28.   global goZoomsText
  29.   global goSeconds
  30.   global goFPS
  31.   global goBaseLine
  32.   global goSizeMin
  33.   global goSizeMax
  34.   global goDelayEnter
  35.   global goDelayHold
  36.   global goCycles
  37.   
  38.   set ioFieldList = [goZoomsText, goSeconds, goFPS, goSizeMin, goSizeMax,¼
  39.                               goBaseLine, goDelayEnter, goDelayHold, goCycles]
  40.   set ikMotionIn = 1
  41.   set ikMotionOut = 2
  42.   set ikMotionOutThenIn = 3
  43.   set ikMotionInThenOut = 4
  44.   
  45.   set iCurrentMotionStyleIndex = ikMotionIn
  46.   set iCurrentVisualStyleIndex = 1
  47.   set iFieldFocus = 1
  48.   set iFirstTime = TRUE
  49.   
  50.   return me
  51. end birth
  52.  
  53. on mInit me
  54.   global goSeconds
  55.   global goFPS
  56.   global goBaseLine
  57.   global goSizeMin
  58.   global goSizeMax
  59.   global goDelayEnter
  60.   global goDelayHold
  61.   global goCycles
  62.   global goZooms
  63.   global goMarkFrame
  64.   global goVisualStyles
  65.   global goMotionStyles
  66.   global goScoreMgr
  67.   
  68.   -- CheckMark parameter: channel
  69.   mInit(goMarkFrame, 4)  -- channel
  70.   
  71.   if iFirstTime then  -- use intellegent defaults
  72.     mSetValue(goSeconds, 5)
  73.     mSetValue(goFPS, 5)
  74.     set defaultBaseLine = integer(mGetStageHeight(goScoreMgr) / 2)
  75.     mSetValue(goBaseLine, defaultBaseLine)
  76.     mSetValue(goSizeMin, 1)
  77.     mSetValue(goSizeMax, 100)
  78.     mSetValue(goDelayEnter, 0)
  79.     mSetValue(goDelayHold, 0)
  80.     mSetValue(goCycles, 1)
  81.     mSetValue(goMarkFrame, TRUE)
  82.     set iFirstTime = FALSE
  83.     
  84.   else  -- use values saved from when we last left
  85.     mSetValue(goSeconds, iSaveSeconds)
  86.     mSetValue(goFPS, iSaveFPS)
  87.     mSetValue(goBaseLine, iSaveBaseline)
  88.     mSetValue(goSizeMin, iSaveSizeMin)
  89.     mSetValue(goSizeMax, iSaveSizeMax)
  90.     mSetValue(goDelayEnter, iSaveDelayEnter)
  91.     mSetValue(goDelayHold, iSaveDelayHold)
  92.     mSetValue(goCycles, iSaveCycles)
  93.     mSetValue(goMarkFrame, iSaveMark)
  94.   end if
  95.   
  96.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  97.   
  98.   -- RadioButtons parameters: channel, nChannels, rightAnswer, default
  99.   set goMotionStyles = 0
  100.   set goMotionStyles = birth(script "RadioButton",  26, 4, 0, iCurrentMotionStyleIndex)
  101.   
  102.   -- VisualStyles Params: castNum, default, nItems, channel
  103.   if the machineType < 256 then
  104.     mInit(goVisualStyles, the number of cast "ZoomsVisualStylesMac", ¼
  105.                iCurrentVisualStyleIndex, 8, 19)
  106.   else
  107.     mInit(goVisualStyles, the number of cast "ZoomsVisualStylesPC", ¼
  108.                iCurrentVisualStyleIndex, 8, 19)
  109.   end if
  110.   
  111.   -- For keystroke validity checking
  112.   set the keydownscript =  "mCheckKey(goZooms)"
  113.   
  114. end mInit 
  115.  
  116. on mSetFieldFocus me, oWhom
  117.   set where = getOne(ioFieldList, oWhom)
  118.   if where = 0 then
  119.     alert("Internal error - mSetFieldFocus could not find object")
  120.     return
  121.   end if
  122.   
  123.   set iFieldFocus = where  
  124.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  125.   
  126. end mSetFieldFocus
  127.  
  128. on mCheckKey me
  129.   if the Key = TAB then -- change focus to the next field
  130.     set iFieldFocus = IncrMod(iFieldFocus, count(ioFieldList))
  131.     set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  132.     pass  -- pass the event so the hilight goes to the next field  
  133.   else
  134.     if iFieldFocus = 1 then -- the text entry field, allow anything
  135.       pass
  136.     else  -- numeric fields, only allow digits
  137.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE)  then
  138.         pass
  139.       else
  140.         dontPassEvent -- restrict only to digits.
  141.       end if
  142.     end if
  143.   end if
  144. end mCheckKey
  145.  
  146. on mSetNewMotionStyle me, theNewStyleIndex
  147.   set iCurrentMotionStyleIndex = theNewStyleIndex
  148. end mSetNewMotionStyle
  149.  
  150. on mSetNewVisualStyle me, theNewStyleIndex
  151.   set iCurrentVisualStyleIndex = theNewStyleIndex
  152. end mSetNewVisualStyle
  153.  
  154.  
  155.  
  156. on mValidate me
  157.   global goSizeMin
  158.   global goSizeMax
  159.   
  160.   if mGetValue(goSizeMin) > mGetValue(goSizeMax) then
  161.     alert("The minimum size must be less than the maximum size.")
  162.     return FALSE
  163.   end if
  164.   
  165.   -- Attempt to validate the last field of focus
  166.   set lastFieldOKFlag = mValidate(ioFIeldFocus)
  167.   return lastFieldOKFlag
  168. end mValidate
  169.  
  170.  
  171. on mCreate me
  172.   global goMarkFrame
  173.   global goMotionStyles
  174.   global goVisualStyles
  175.   global goScoreMgr
  176.   global goCastMgr
  177.   global gDevelopmentFlag
  178.   global gCastNumTextAsBitmap
  179.   
  180.   if not(mValidate(me)) then
  181.     return
  182.   end if
  183.   if field("ZoomsText") = EMPTY then
  184.     alert("Please enter some text for the Zoom.")
  185.     return
  186.   end if
  187.   
  188.   tell the stage
  189.     set theStageFrame = the frame
  190.   end tell
  191.   
  192.   set castNumVisualStyle = mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  193.   set theVisualStyleName = the name of cast castNumVisualStyle
  194.   set theFont = word 2 of theVisualStyleName
  195.   set theSize = word 3 of theVisualStyleName
  196.   set theSeconds = integer(field "Seconds")
  197.   
  198.   set fps = integer(field "FPS")
  199.   set baseLine = integer(field "BaseLine")
  200.   set delayEnter = integer(field "DelayEnter")
  201.   set delayHold = integer(field "DelayHold")
  202.   set nCycles = integer(field "Cycles")
  203.   set markFirst = mGetValue(goMarkFrame)
  204.   set sizeMin = integer(field "SizeMin")
  205.   set sizeMax = integer(field "SizeMax")
  206.   set nFrames = integer(theSeconds * fps)
  207.   
  208.   
  209.   -- Call the ScoreMgr to set up the score, # of frames, and 1 channel
  210.   --  set nTotalFrames = (delayEnter + nFrames + delayHold) * nCycles
  211.   
  212.   if delayHold > 0 then
  213.     set nTotalFrames = (nFrames + 1)*nCycles
  214.   else
  215.     set nTotalFrames = nFrames*nCycles
  216.   end if
  217.   
  218.   if not(mInit(goScoreMgr, nTotalFrames, 1)) then
  219.     return
  220.   end if
  221.   
  222.   set theCh = mGetNextSelectedChannel(goScoreMgr)
  223.   set theFrameNum = mGetStartFrame(goScoreMgr)
  224.   
  225.   set castNumSource = mModifyRichTextCM(goCastMgr, ¼
  226.                 the text of field "ZoomsText", theFont, theSize)
  227.   if castNumSource = 0 then  -- error
  228.     return
  229.   end if  
  230.   
  231.   -- The following does an effective "Convert to bitmap" into a 
  232.   -- known bitmap cast member.
  233.   set the picture of member gCastNumTextAsBitmap = ¼
  234.         the picture of member castNumSource
  235.   set widthOfTextAsBitmap = float(the width of member gCastNumTextAsBitmap)
  236.   set heightOfTextAsBitmap = float(the height of member gCastNumTextAsBitmap)
  237.   
  238.   
  239.   -- Do specific calculations depending on motion style  
  240.   
  241.   set pctMin = float(sizeMin) / 100.
  242.   set pctMax = float(sizeMax) / 100.
  243.   set pctInc = (pctMax - pctMin) / float(nFrames - 1)
  244.   
  245.   
  246.   if (iCurrentMotionStyleIndex = ikMotionIn)  or (iCurrentMotionStyleIndex = ikMotionOut) then    
  247.     set nFrames1 = nFrames
  248.     set nFrames2 = 0
  249.   else
  250.     set nFrames1 = integer(nFrames / 2)
  251.     set nFrames2 = nFrames - nFrames1
  252.     set pctInc = pctInc * 2  -- must double to do this in half the frames
  253.   end if
  254.   
  255.   if (iCurrentMotionStyleIndex = ikMotionIn) or ¼
  256.       (iCurrentMotionStyleIndex = ikMotionInThenOut) then 
  257.     
  258.     set pctStart1 = pctMin
  259.     set pctInc1 = pctInc
  260.     set pctStart2 = pctMax
  261.     set pctInc2 = pctInc * -1.0
  262.     
  263.   else  -- Out or OutThenIn
  264.     set pctStart1 = pctMax
  265.     set pctInc1 = pctInc * -1.0
  266.     set pctStart2 = pctMin
  267.     set pctInc2 = pctInc
  268.     
  269.   end if
  270.   
  271.   set theForeColor  = 255
  272.   set theBackColor  = 0
  273.   
  274.   --  Copy the cast member into the source movie's cast
  275.   
  276.   set castNumTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  277.   copyToClipBoard member gCastNumTextAsBitmap
  278.   tell the stage
  279.     pasteClipboardInto member castNumTarget
  280.     set the name of member castNumTarget  = "BitMap" && string(the ticks)
  281.   end tell
  282.   
  283.   --  Finally we are ready to generate frames
  284.   
  285.   -- Mark first frame upon request
  286.   if markFirst  then
  287.     set theLabel  = "AW.Zoom." & word 1 of the text of field "ZoomsText" & " " & ¼
  288.               mGetGeneratedScoreSelection(goScoreMgr)
  289.     mWriteFrameLabel(goScoreMgr, theFrameNum, theLabel)
  290.   end if
  291.   
  292.   -- Generate the score fragment
  293.   repeat with thisCycle = 1 to nCycles
  294.     set xLoc = round(mGetStageWidth(goScoreMgr) / 2)
  295.     set yLoc = baseline    
  296.     
  297.     set currentPct = pctStart1
  298.     set theWidth = currentPct * widthOfTextAsBitmap
  299.     set theHeight = currentPct * heightOfTextAsBitmap
  300.     
  301.     -- Insert delay at entry upon request  
  302.     --    if  delayEnter > 0  then 
  303.     --      repeat with f = 1 to delayEnter        
  304.     --        mWriteFrameDelay(goScoreMgr, theFrameNum, 1)
  305.     --        mWriteSprite(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  306. --                     theForeColor, theBackColor, xLoc, yLoc, round(theWidth), round(theHeight))      
  307.     --        set theFrameNum = theFrameNum + 1
  308.     --      end repeat      
  309.     --    end if 
  310.     
  311.     if delayEnter > 0 then
  312.       mWriteFrameDelay(goScoreMgr, theFrameNum, delayEnter)
  313.       mWriteFrameTempo(goScoreMgr, (theFrameNum + 1), fps)
  314.     else 
  315.       mWriteFrameTempo(goScoreMgr, theFrameNum , fps)
  316.       mWriteFrameTempo(goScoreMgr, (theFrameNum + 1), 0)
  317.     end if
  318.     
  319.     --    mWriteFrameTempo(goScoreMgr, theFrameNum, fps)
  320.     -- Generate the first part of the zoom
  321.     tell the stage
  322.       beginRecording
  323.         
  324.         repeat with thisFrame = 1 to nFrames1
  325.           set theWidth = integer(theWidth +.49)
  326.           set theHeight = integer(theHeight + .49)
  327.           -- put theFrameNum &&theCh  && castNumberTarget  && xLoc && yLoc     
  328.           mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  329.                      theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight)      
  330.           set theFrameNum = theFrameNum + 1
  331.           set currentPct = currentPct + pctInc1
  332.           set theWidth = currentPct * widthOfTextAsBitmap
  333.           set theHeight = currentPct * heightOfTextAsBitmap
  334.           
  335.         end repeat
  336.       endRecording
  337.     end tell
  338.     
  339.     -- insert delay  upon request
  340.     --    if  delayHold > 0  then 
  341.     --      repeat with f = 1 to delayHold        
  342.     --        mWriteFrameDelay(goScoreMgr, theFrameNum, 1)
  343.     --        mWriteSprite(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  344. --                     theForeColor, theBackColor, xLoc, yLoc, integer(theWidth), integer(theHeight))      
  345.     --        set theFrameNum = theFrameNum + 1
  346.     --      end repeat      
  347.     --    end if 
  348.     
  349.     if delayHold > 0 then
  350.       mWriteFrameDelay(goScoreMgr, theFrameNum, delayHold)
  351.       mWriteFrameTempo(goScoreMgr, (theFrameNum + 1), 0)
  352.       mWriteSprite(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  353.                      theForeColor, theBackColor, xLoc, yLoc, integer(theWidth), integer(theHeight))      
  354.       set theFrameNum = theFrameNum + 1
  355.     end if
  356.     
  357.     -- Generate the second part of the zoom if there is one
  358.     if nFrames2 > 0 then
  359.       set currentPct = pctStart2
  360.       set theWidth = currentPct * widthOfTextAsBitmap
  361.       set theHeight = currentPct * heightOfTextAsBitmap
  362.       mWriteFrameTempo(goScoreMgr, theFrameNum, fps)
  363.       tell the stage
  364.         beginRecording
  365.           
  366.           repeat with thisFrame = 1 to nFrames2
  367.             set theWidth = integer(theWidth +.49)
  368.             set theHeight = integer(theHeight + .49)
  369.             -- put theFrameNum &&theCh  && castNumberTarget  && xLoc && yLoc     
  370.             mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  371.                      theForeColor, theBackColor, xLoc, yLoc, theWidth, theHeight)      
  372.             set theFrameNum = theFrameNum + 1
  373.             set currentPct = currentPct + pctInc2
  374.             set theWidth = currentPct * widthOfTextAsBitmap
  375.             set theHeight = currentPct * heightOfTextAsBitmap
  376.           end repeat
  377.         endRecording
  378.       end tell
  379.     end if
  380.     
  381.   end repeat  -- nCycles
  382.   
  383.   
  384.   go  label("Zooms") + 2  -- to display reselect button
  385.   
  386.   if not(gDevelopmentFlag) then
  387.     tell the stage
  388.       go frame theStageFrame
  389.     end tell
  390.   end if 
  391.   
  392.   mClean(goScoreMgr)
  393.   
  394. end mCreate
  395.  
  396.  
  397.  
  398. on mCleanup me
  399.   global goMotionStyles
  400.   global goSeconds
  401.   global goFPS
  402.   global goBaseLine
  403.   global goSizeMin
  404.   global goSizeMax
  405.   global goDelayEnter
  406.   global goDelayHold
  407.   global goCycles
  408.   global goMarkFrame
  409.   
  410.   mCleanup(goMotionStyles)
  411.   
  412.   set iSaveSeconds =  mGetValue(goSeconds)
  413.   set iSaveFPS = mGetValue(goFPS)
  414.   set iSaveBaseLine = mGetValue(goBaseLine)
  415.   set iSaveSizeMin = mGetValue(goSizeMin)
  416.   set iSaveSizeMax = mGetValue(goSizeMax)
  417.   set iSaveDelayEnter = mGetValue(goDelayEnter)
  418.   set iSaveDelayHold = mGetValue(goDelayHold)
  419.   set iSaveCycles = mGetValue(goCycles)  
  420.   set iSaveMark = mGetValue(goMarkFrame)  
  421.   mCleanup(goMarkFrame)
  422. end mCleanup
  423.  
  424.